<template>
	<view class="container">
		<view class="head-wrap">
			<view class="head-box">
				<navigator url="setting/avatar" class="avator-box">
					<image v-if="model.avatar" mode="widthFix" :src="$api.loadFile(model.avatar)"></image>
					<text v-else class="icon iconfont icon-user-full"></text>
				</navigator>
				<view class="info-box">
					<text v-if="model.userName" class="tit">欢迎您，{{model.realName?model.realName:model.userName}}</text>
					<text v-else class="tit">欢迎您，游客</text>
					<view class="label">
						<text v-if="model.userName" class="txt">{{model.groupTitle}}</text>
						<text v-else class="txt">未登录</text>
					</view>
				</view>
			</view>
			<view class="count-item">
				<navigator url="balance/list" class="list-box">
					<text class="num">{{model.amount?model.amount:0.00}}</text>
					<text class="title">余额</text>
				</navigator>
				<navigator url="coupon/list" class="list-box">
					<text class="num">{{model.coupon?model.coupon:'0'}}</text>
					<text class="title">优惠券</text>
				</navigator>
				<navigator url="invoice/list" class="list-box">
					<text class="num">{{model.point}}</text>
					<text class="title">发票</text>
				</navigator>
			</view>
		</view>

		<view class="group-box">
			<view class="order-item">
				<navigator url="../order/list" class="list-box">
					<text class="icon iconfont icon-order"></text>
					<text class="title">全部订单</text>
				</navigator>
				<navigator url="../order/list?state=1" class="list-box">
					<text class="icon iconfont icon-payment"></text>
					<text class="title">待付款</text>
				</navigator>
				<navigator url="../order/list?state=3" class="list-box">
					<text class="icon iconfont icon-deliver"></text>
					<text class="title">待收货</text>
				</navigator>
				<navigator url="../refund/list" class="list-box">
					<text class="icon iconfont icon-refund"></text>
					<text class="title">售后/退款</text>
				</navigator>
			</view>
		</view>

		<view class="group-box">
			<view class="item-list">
				<navigator url="balance/list" class="list-box">
					<text class="icon big orange iconfont icon-balance"></text>
					<text class="remark opt">我的钱包</text>
				</navigator>
				<navigator url="address/list" class="list-box">
					<text class="icon big green iconfont icon-address-full"></text>
					<text class="remark opt">收货地址</text>
				</navigator>
				<navigator url="favorite/list" class="list-box">
					<text class="icon big blue iconfont icon-star-full"></text>
					<text class="remark opt">我的收藏</text>
				</navigator>
				<navigator v-if="!isMerchant" url="../merchant/add" class="list-box">
					<text class="icon big green iconfont icon-user-full"></text>
					<text class="remark opt">申请经销</text>
				</navigator>
				<navigator v-if="isMerchant" url="warehouse/list" class="list-box">
					<text class="icon big green iconfont icon-user-full"></text>
					<text class="remark opt">我的酒库</text>
				</navigator>
				<navigator url="setting/index" class="list-box">
					<text class="icon big red iconfont icon-seting-full"></text>
					<text class="remark opt">账户设置</text>
				</navigator>

			</view>
		</view>

		<view class="group-box">
			<view class="foot-box">
				<text v-if="model" @click="outLogin" class="btn">退出登录</text>
				<navigator v-else url="login" class="btn">去登录</navigator>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {},
				merchant: {},
				isMerchant: false,
			}
		},
		methods: {
			//初始化数据
			async initData() {
				let _this = this;
				//正在加载
				uni.showLoading({
					title: '加载中'
				});
				//获取会员信息
				await _this.$api.request({
					url: "/account/member",
				}).then((res) => {
					_this.model = res.data;
				});

				//获取店铺信息
				await _this.$api.request({
					url: "/account/merchant",
				}).then((res) => {					
					_this.merchant = res.data;
					if (_this.merchant.isLock == 0) {
						_this.isMerchant = true;
					}

				}).catch(err => {});

				//获取会员优惠券数量
				await _this.$api.request({
					url: "/account/shop/coupon/count",
				}).then((res) => {
					_this.$set(_this.model, 'coupon', res.data);
				});
				//关闭加载
				uni.hideLoading();
			},
			//注销登录
			outLogin() {
				uni.removeStorageSync('qymall_client_token');
				uni.navigateTo({
					url: 'login'
				});
			}
		},
		//页面初始化
		onShow(options) {
			this.initData();
		}
	}
</script>

<style lang="scss">
	.head-wrap {
		position: relative;
		width: 100%;
		height: 348rpx;
		overflow: hidden;

		&:before {
			content: "";
			position: absolute;
			display: block;
			top: -50%;
			left: -50%;
			right: -50%;
			bottom: 40rpx;
			background: linear-gradient(to bottom, #f63515, #e43130);
			border-radius: 50%;
		}

		&:after {
			content: "";
			position: absolute;
			display: block;
			top: -120%;
			left: -50%;
			right: 30%;
			bottom: 24rpx;
			background: rgba($color: #fff, $alpha: 0.1);
			border-radius: 50%;
		}

		.head-box {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 50rpx 24rpx 0 50rpx;

			.avator-box {
				flex-shrink: 0;
				display: flex;
				justify-content: center;
				align-items: center;
				width: 128rpx;
				height: 128rpx;
				box-sizing: border-box;
				border-radius: 50%;
				border: 4rpx solid #fff;
				background: #fff;
				overflow: hidden;
				z-index: 2;

				.icon {
					color: #ccc;
					font-size: 60rpx;
				}

				image {
					width: 100%;
				}
			}

			.info-box {
				flex-grow: 1;
				display: flex;
				justify-content: flex-start;
				flex-direction: column;
				margin-left: 20rpx;

				.tit {
					margin-bottom: 16rpx;
					color: #fff;
					font-size: 34rpx;
					line-height: 1;
				}

				.label {
					.txt {
						padding: 4rpx 20rpx;
						color: #ebebeb;
						font-size: 24rpx;
						line-height: 28rpx;
						background: rgba($color: #fff, $alpha: 0.3);
						border-radius: 10rpx;
					}

				}
			}
		}

		.count-item {
			display: flex;
			justify-content: space-around;
			position: absolute;
			left: 24rpx;
			right: 24rpx;
			bottom: 0;
			padding: 24rpx;
			border-radius: 20rpx;
			background: #fff;
			z-index: 1;

			.list-box {
				display: flex;
				justify-content: space-around;
				align-items: center;
				flex-direction: column;

				.num {
					margin-bottom: 8rpx;
					color: #333;
					font-size: 32rpx;
				}

				.title {
					color: #75787d;
					font-size: 24rpx;
				}
			}
		}
	}

	.order-item {
		display: flex;
		justify-content: space-between;
		padding: 24rpx;
		border-radius: 20rpx;
		background: #fff;

		.list-box {
			width: 120rpx;
			height: 120rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			flex-direction: column;

			.icon {
				margin-bottom: 18rpx;
				color: #ff0000;
				font-size: 44rpx;
			}

			.title {
				color: #666;
				font-size: 24rpx;
			}
		}
	}

	.foot-box {
		display: flex;
		justify-content: space-between;
		flex-direction: column;

		.btn {
			margin-bottom: 24rpx;
			box-sizing: border-box;
			color: #fa436a;
			font-size: 28rpx;
			line-height: 76rpx;
			text-align: center;
			border-radius: 76rpx;
			background: #fff;
		}
	}
</style>